﻿#include "widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    m_node = new QRemoteObjectNode(this);
    m_node->connectToNode(QUrl("local:myrpc"));

    m_rpc = m_node->acquire<MyRPCReplica>();

    connect(m_node,&QRemoteObjectNode::error,[](){
        qDebug() << "connect error";
    });

    connect(m_rpc,&MyRPCReplica::msgFromServer,this,&Widget::onMessageFromServer);

    connect(m_rpc,&MyRPCReplica::textChanged,[](){
        qDebug() << "text changed";
    });
}


Widget::~Widget()
{
}

void Widget::onMessageFromServer(const QString &msg)
{
    qDebug() << "clienB recv" << msg;

    /* 可以直接获取属性值，也可以链接信号，这样可是实时获取更新信息（qml属性绑定是依赖信号机制的)，这里类似轮训 */
    qDebug() << m_rpc->text();
}
